<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const arr = [1, 2, 3, 4, 5]

        Array.prototype.myForEach = function (callback) {
        //     // 一般传入一个函数，你肯定会去调用他，否则你传他干嘛
            // console.log(this)
            for (let i = 0; i < this.length; i++) {
                callback(this[i], i, this)
            }
        }

        // const res = arr.myForEach((item, index, arr) => {
        //     console.log(item, index, arr)
        // })
        // console.log(res)
const res = arr.myForEach((item,index,arr) => {
    console.log(item,index,arr)
})
console.log(res)
        // Array.prototype.myFilter = function (callback) {
        //     const result = []
        //     for (let i = 0; i < this.length; i++) {
        //         const flag = callback(this[i], i, this)
        //         if (flag) {
        //             result.push(this[i])
        //         }
        //     }
        //     return result
        // }

        // const res2 = arr.myFilter(item => item > 3)
        // console.log(res2)
    </script>
</body>

</html>

